#include <stdio.h>

/***********************************
 * 棋盘规模：2^k (<100)             *
 * 残缺L块标号： count              *
 * scale = 2^k 棋盘规模             *
 * (hx, hy) 棋盘或子棋盘第一块坐标   *
 * (dx, dy) 残缺块坐标或伪残缺块坐标 *
 *=================================*/
int count = 0;
int board[100][100];
int board_fixed(int hx, int hy, int dx, int dy, int scale);
int board_print(int size);

int main(int argc, const char args[]) {
	int n;
	int x, y;
	printf("please definit board scale(=2^k) and black chess's position(x, y):\n");
	scanf("%d, %d, %d", &n, &x, &y);
	board[x][y] = -1;
	board_fixed(0, 0, x, y, n);
	board_print(n);

	return 0;
}

int board_print(int size) {
	int i, j;
	for (i = 0; i < size; ++i) {
		for (j = 0; j < size; ++j) {
			printf("%5d ", board[i][j]);
		}
		printf("\n");
	}

	return 0;
}

int board_fixed(int hx, int hy, int dx, int dy, int size) {
	int s;
	if (size < 2) return 0;
	s = size / 2;

	// true black chess at left top block
	if ( dx < (hx+s) && dy < (hy+s) ) {
		board[hx+s-1][hy+s] = count;
		board[hx+s][hy+s-1] = count;
		board[hx+s][hy+s] = count;

		++count;

		board_fixed(hx, hy, dx, dy, s);             // lt
		board_fixed(hx, hy+s, hx+s-1, hy+s, s);     // rt
		board_fixed(hx+s, hy, hx+s, hy+s-1, s);     // lb
		board_fixed(hx+s, hy+s, hx+s, hy+s, s);     // rb
	}
	// right top
	else if ( dx < (hx+s) && dy >= (hy+s) ) {
		board[hx+s-1][hy+s-1] = count;
		board[hx+s][hy+s-1] = count;
		board[hx+s][hy+s] = count;

		++count;

		board_fixed(hx, hy+s, dx, dy, s);           // rt
		board_fixed(hx, hy, hx+s-1, hy+s-1, s);     // lt
		board_fixed(hx+s, hy, hx+s, hy+s-1, s);     // lb
		board_fixed(hx+s, hy+s, hx+s, hy+s, s);     // rb
	}
	// left bottom
	else if ( dx >= (hx+s) && dy < (hy+s) ) {
		board[hx+s-1][hy+s-1] = count;
		board[hx+s-1][hy+s] = count;
		board[hx+s][hy+s] = count;

		++count;

		board_fixed(hx+s, hy, dx, dy, s);           // lb
		board_fixed(hx, hy, hx+s-1, hy+s-1, s);     // lt
		board_fixed(hx, hy+s, hx+s-1, hy+s, s);     // rt
		board_fixed(hx+s, hy+s, hx+s, hy+s, s);     // rb
	}
	else if ( dx >= (hx+s) && dy >= (hy+s) ) {
		board[hx+s-1][hy+s-1] = count;
		board[hx+s-1][hy+s] = count;
		board[hx+s][hy+s-1] = count;

		++count;

		board_fixed(hx+s, hy+s, dx, dy, s);         // rb
		board_fixed(hx, hy, hx+s-1, hy+s-1, s);     // lt
		board_fixed(hx, hy+s, hx+s-1, hy+s, s);     // rt
		board_fixed(hx+s, hy, hx+s, hy+s-1, s);     // lb
	}

	return 0;
}